package cc.mrbird.febs.power.controller;


import cc.mrbird.febs.common.utils.R;
import cc.mrbird.febs.power.entity.ColumnInfo;
import cc.mrbird.febs.power.service.IColumnInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author MrBird
 */
@RestController
@RequestMapping("/power/column-info")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ColumnInfoController {

    private final IColumnInfoService iColumnInfoService;

    /**
     * 分页获取行信息
     * @param page
     * @param columnInfo
     * @return
     */
    @GetMapping("/page")
    public R getColumnInfoByPage(Page page,ColumnInfo columnInfo) {
        return R.ok(iColumnInfoService.page(page, Wrappers.<ColumnInfo>lambdaQuery()
                .like(columnInfo.getName()!=null,ColumnInfo::getName,columnInfo.getName())
                .eq(columnInfo.getType()!=null,ColumnInfo::getType,columnInfo.getType())));
    }

   /**
     * 获取所有行信息
     * @return
     */
    @GetMapping
    public R getColumnInfo() {
        return R.ok(iColumnInfoService.list());
    }

    /**
     * 新增行操作
     * @param columnInfo
     * @return
     */
    @PostMapping("/ColumnInfoAdd")
    public R ColumnInfoAdd(ColumnInfo columnInfo) {
        return R.ok(iColumnInfoService.save(columnInfo));
    }

    /**
     * 修改行操作
     * @param columnInfo
     * @return
     */
    @PutMapping("/ColumnInfoEdit")
    public R ColumnInfoEdit(ColumnInfo columnInfo) {
        return R.ok(iColumnInfoService.updateById(columnInfo));
    }

    /**
     * 删除行操作
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R ColumnInfoDel(@PathVariable Integer id) {
        return R.ok(id);
    }

}
